home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Syn Text Editor 2.1.0.46 / synsetup-2.1.0.46.exe / {app} / scripts / xmlvalidate.vbs < prev   
Text File  |  2003-08-13  |  4KB  |  98 lines

  1. ' Caption: XML validate...|
  2. ' Hint: Valida un documento XML|
  3. ' Icon: xmlvalidate.ico|
  4. '
  5. '  
  6. '  Copyright (C) 2000-2003, Magoga Demis. All rights reserved.
  7. '
  8. '  The contents of this file are subject to the Mozilla Public License
  9. '  Version 1.1 (the "License"); you may not use this file except in compliance
  10. '  with the License. You may obtain a copy of the License at
  11. '  http://www.mozilla.org/MPL/
  12. '
  13. '  Software distributed under the License is distributed on an "AS IS" basis,
  14. '  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  15. '  the specific language governing rights and limitations under the License.
  16. '
  17. '  The Initial Developer of the Original Code is Magoga Demis.
  18. '  Portions created by Magoga Demis are Copyright (C) 2000-2003 Magoga Demis.
  19. '  All Rights Reserved.
  20. '
  21. '  Contributor(s): .
  22. '
  23. '  Alternatively, the contents of this file may be used under the terms of the
  24. '  GNU General Public License Version 2 or later (the "GPL"), in which case
  25. '  the provisions of the GPL are applicable instead of those above.
  26. '  If you wish to allow use of your version of this file only under the terms
  27. '  of the GPL and not to allow others to use your version of this file
  28. '  under the MPL, indicate your decision by deleting the provisions above and
  29. '  replace them with the notice and other provisions required by the GPL.
  30. '  If you do not delete the provisions above, a recipient may use your version
  31. '  of this file under either the MPL or the GPL.
  32. '
  33. ' $Id: xmlvalidate.vbs,v 1.2.2.5 2003/08/13 00:38:45 neum Exp $
  34.  
  35. ' Validate the Active XML Document
  36. '
  37. ' If you need, here the parseError properties:
  38. '
  39. ' Error #:               parseError.errorCode
  40. ' Description:           parseError.reason
  41. ' In file:               parseError.url
  42. ' Line #:                parseError.line
  43. ' Character # in line:   parseError.linepos
  44. ' Character # in file:   parseError.filepos
  45. ' Source line:           parseError.srcText
  46.  
  47.  
  48. option explicit
  49.  
  50. on error resume next
  51.  
  52. ' microsoft parser version, you can add new version
  53. ' you can download msxml parser at http://www.microsoft.com/
  54. Dim msParserVersion
  55. msParserVersion = Array("Msxml.DOMDocument","Msxml2.DOMDocument")
  56.  
  57. sub Main(dummy)
  58.   if Documents.Count = 0 then
  59.     MsgBox "No Document open.", vbCritical
  60.     exit sub
  61.   end if
  62.   dim objDOMDoc
  63.   dim version
  64.   dim i
  65.   version= "null"
  66.  
  67.   ' i try to create parser object and save the version
  68.   for i = 0 to ubound(msParserVersion)
  69.     if (IsObject(CreateObject(msParserVersion(i)))) <> "" then
  70.       version=msParserVersion(i)
  71.       exit for
  72.     end if
  73.   next
  74.  
  75.   ' if the microsoft component is not installed i invite to do
  76.   if version = "null" then
  77.     MsgBox ("You need Msxml parser" & vbCrLf &   _
  78.             "You can find it at http://www.microsoft.com/")
  79.     exit sub
  80.   end if
  81.  
  82.   ' i set the active document text to the parser and then:
  83.   ' - if all is ok a message dialog is show
  84.   ' - if an error is raised a message dialog is show and the line is highlight
  85.   Set objDOMDoc= CreateObject(version)
  86.     objDOMDoc.async = false
  87.     if (objDOMDoc.loadXML(ActiveDocument.Text))    then          
  88.       MsgBox "Document is well formed and valid", vbInformation
  89.     else    
  90.       MsgBox "Error in line: " & objDOMDoc.parseError.Line & vbCrLf & _
  91.             "Reason: " & objDOMDoc.parseError.reason, vbExclamation
  92.     ActiveDocument.HighlightLine objDOMDoc.parseError.Line, objDOMDoc.parseError.linepos, &hff
  93.     end if
  94.  
  95. end sub
  96.  
  97.  
  98.